package critters;



import java.util.ArrayList;
import java.awt.Color;
import info.gridworld.grid.Grid;
import info.gridworld.grid.Location;

public class QuickCrab extends CrabCritter {

	public QuickCrab()
    {
        setColor(Color.RED);
    }

    public ArrayList<Location> getMoveLocations()
    {
        ArrayList<Location> locs = new ArrayList<Location>();
        int[] dirs =
            { Location.LEFT, Location.RIGHT };
        for (Location loc : getTwoStepsInDirections(dirs))
            if (getGrid().get(loc) == null)
                locs.add(loc);
        if(locs.size() == 0)
        {
        	for (Location loc : getOneStepsInDirections(dirs))
                if (getGrid().get(loc) == null)
                    locs.add(loc);
        }

        return locs;
    }


    public ArrayList<Location> getTwoStepsInDirections(int[] directions)
    {
        ArrayList<Location> locs = new ArrayList<Location>();
        Grid gr = getGrid();
        Location loc = getLocation();
        
        for (int d : directions)
        {
            Location neighborLoc = loc.getAdjacentLocation(getDirection() + d);
            if (gr.isValid(neighborLoc) ){
            	if(getGrid().get(neighborLoc) == null && gr.isValid(neighborLoc.getAdjacentLocation(getDirection()+d)))
            		locs.add(neighborLoc.getAdjacentLocation(getDirection()+d));
            	
            }	
        }
        return locs;
    }  
    
    public ArrayList<Location> getOneStepsInDirections(int[] directions)
    {
        ArrayList<Location> locs = new ArrayList<Location>();
        Grid gr = getGrid();
        Location loc = getLocation();
        
        for (int d : directions)
        {
            Location neighborLoc = loc.getAdjacentLocation(getDirection() + d);
            if (gr.isValid(neighborLoc) )
            	locs.add(neighborLoc);
            	
        }
        return locs;
    }  
 
}
